package com.qianclass.talklive.app.json.ImSendMessge;

import com.qianclass.talklive.app.bean.MusicCommandBean;
import com.qianclass.talklive.app.utils.Constant;
import com.qianclass.talklive.app.utils.LogUtil;
import com.qianclass.talklive.app.utils.ThreadUtils;
import com.google.gson.Gson;

import static com.qianclass.talklive.app.activity.VideoActivity.egine;


/**
 * 音频命令的发送
 * {"message":{"type":"whiteboard","whiteboard":{"action":"play","fileid":10017097,"subcommand":"audio","time":55}}}
 * {"message":{"type":"whiteboard","whiteboard":{"action":"pause","fileid":10017097,"subcommand":"audio"}}}
 * {"message":{"type":"whiteboard","whiteboard":{"action":"stop","fileid":10017096,"subcommand":"audio"}}}
 *
 */

public class SendMusicCommandMessage {

    /**
     * @param time
     * @param fileId
     * @param command
     * @param group
     */
    public static void sendMessge(int time, int fileId, String command, final String group) {
        try {

            MusicCommandBean musicCommandBean = new MusicCommandBean();
            MusicCommandBean.MessageBean messageBean = new MusicCommandBean.MessageBean();
            MusicCommandBean.MessageBean.WhiteboardBean whiteboardBean = new MusicCommandBean.MessageBean.WhiteboardBean();

            whiteboardBean.setSubcommand("audio");
            whiteboardBean.setTime(time);
            whiteboardBean.setFileid(fileId);
            whiteboardBean.setAction(command);

            messageBean.setType("whiteboard");
            messageBean.setWhiteboard(whiteboardBean);

            musicCommandBean.setMessage(messageBean);

            Gson gson = new Gson();
            final String jsonString = gson.toJson(musicCommandBean);
            ThreadUtils.runOnSubThread(new Runnable() {
                @Override
                public void run() {
                    egine.SendGroupMessage(Constant.CONTROLMSGTYPE, group, jsonString);
                }
            });
            LogUtil.i("音频" ,jsonString);
        } catch (Exception e){
            LogUtil.i("音频" , "发送信息失败");
        }

    }
}
